﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nablasoft.Console.Utils;
using TfsUtils.Utils;
using TfsUtils.Utils.Concrete;

namespace TfsUtils.Commands
{
    class CommandDef
    {
        private readonly List<Parameter> _commonParameters;

        public CommandDef(List<Parameter> commonParameters)
        {
            _commonParameters = commonParameters;
        }

        public String Name { get; set; }

        public String ClassName { get; set; }

        public ICommand Create(String[] parameters)
        {
            Type t = Type.GetType("TfsUtils.Commands." + ClassName);
            ICommand command = (ICommand)Activator.CreateInstance(t);
            command.SetParameters(_commonParameters, parameters);
            string verbosity = (String) _commonParameters
                .Single(c => c.Name == "verbosity")
                .GetParamValue(parameters);
            ConsoleEnvironment ce = new ConsoleEnvironment((MessageLevel)5 - Int32.Parse(verbosity));
            command.Environment = ce;
            return command;
        }
    }
}
